package pri.black.dogview.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import pri.black.dogview.domain.DeviceStatus;
import pri.black.dogview.domain.TableData;
import pri.black.dogview.domain.vo.CountDateLog;
import pri.black.dogview.mapper.DeviceStatusMapper;
import pri.black.dogview.service.IDeviceStatusService;

import java.util.List;

@Service
public class DeviceStatusImpl extends ServiceImpl<DeviceStatusMapper, DeviceStatus> implements IDeviceStatusService {
    @Override
    public TableData dateCount() {
        List<CountDateLog> countDateLog = getBaseMapper().countDateLog();
        Integer[] datas = new Integer[countDateLog.size()];
        String[] xdatas = new String[countDateLog.size()];
        for (int i = 0; i < countDateLog.size(); i++) {
            datas[i] = countDateLog.get(i).getCount();
            xdatas[i] = countDateLog.get(i).getCountDate().split("-")[3];
        }
        TableData tableData = new TableData();
        tableData.setYdatas(datas);
        tableData.setXdatas(xdatas);
        return tableData;
    }

    @Override
    public TableData batteryCount() {
        List<CountDateLog> countDateLog = getBaseMapper().averagePower();
        Integer[] datas = new Integer[countDateLog.size()];
        String[] xdatas = new String[countDateLog.size()];
        for (int i = 0; i < countDateLog.size(); i++) {
            datas[i] = countDateLog.get(i).getCount();
            xdatas[i] = countDateLog.get(i).getCountDate().split("-")[3];
        }
        TableData tableData = new TableData();
        tableData.setYdatas(datas);
        tableData.setXdatas(xdatas);
        return tableData;
    }
}
